/**
 * 系统人员
 * @auth 鲲鹏
 * @date 2020-04-20
 */
layui.use(['func', 'upload'], function () {

    //声明变量
    var func = layui.func
        , $ = layui.$
        , upload = layui.upload;

    if (A == 'index') {
        //【TABLE列数组】
        var cols = [
            // {type: 'checkbox', fixed: 'left'},
             {field: 'id', width: 80, title: 'ID', align: 'center', sort: true}
            // , {field: 'realName', width: 100, title: '真实姓名', align: 'center'}
            , {field: 'nickName', width: 100, title: '昵称', align: 'center'}
            , {
                field: 'gender', width:100, title: '性别', align: 'center', templet(d) {
                    var cls = "";
                    if (d.gender == 1) {
                        // 男
                        cls = "layui-btn-normal";
                    } else if (d.gender == 2) {
                        // 女
                        cls = "layui-btn-danger";
                    } else if (d.gender == 3) {
                        // 保密
                        cls = "layui-btn-warm";
                    }
                    return '<span class="layui-btn ' + cls + ' layui-btn-xs">' + d.genderName + '</span>';
                }
            }
            , {
                field: 'avatar', title: '头像', align: 'center', templet: function (d) {
                    var avatarStr = "";
                    if (d.avatarUrl) {
                        avatarStr = '<a href="' + d.avatarUrl + '" target="_blank"><img src="' + d.avatarUrl + '" height="26" /></a>';
                    }
                    return avatarStr;
                }
            }
            , {field: 'cityName', width: 150, title: '所属城市', align: 'center'}
            , {field: 'mobile', width: 130, title: '手机号码', align: 'center'}
            , {
                field: 'idCard', width: 130, title: '身份证', align: 'center', templet: function (d) {
                    return d.idCard ? d.idCard.replace(/(\d{6})(\d+)(\d{4})/g, "$1******$3") : "";
                }
            }
            // , {field: 'status', width: 100, title: '状态', align: 'center', templet: '#statusTpl'}
            , {fixed: 'right', width: 150, title: '功能操作', align: 'center', toolbar: '#toolBar'}
        ];

        //【渲染TABLE】
        func.tableIns(cols, "tableList");

        //【设置弹框】
        func.setWin("用户");

        //【设置状态】
        func.formSwitch('status', null, function (data, res) {
            console.log("开关回调成功");
        });
    } else if(A === "edit") {
        upload.render({
            elem: "#upload",
            url: '/api/upload',
            done: function (res, index, upload) {
                let item = this.item;
                $("#image_preview").attr("src", res.path);
                $("input[name=image]").val(res.path);
            }
        })
    }
});
